package com.atguigu.amqp.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : leimingchao
 * @date Date : 2021年10月26日 0:04
 */
@Configuration
public class MyAMQPConfig {

    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    /**如果RabbitMQ没有这个队列，交换机，绑定关系会自动创建
     * 其他都一样
     * @return
     */
    @Bean
    public Queue helloQueue() {
        return new Queue("order-queue",true,false,false,null);
    }

    @Bean
    public Exchange orderExchange() {
        return new DirectExchange("order-exchange",true,false,null);
    }

    @Bean
    public Binding orderBinding() {
        return new Binding("order-queue",Binding.DestinationType.QUEUE,"order-exchange","createOrder",null);
    }
}
